﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Telerik.Web.UI;
using System.IO;
using KPIS.GERP.ESS.BLL;
using KPIS.GERP.ESS.MODEL;

namespace KPIS.GERP.ESS.APP.App_UI.Forms
{
    public partial class ChangePassword : System.Web.UI.Page
    {
        B_SECURITY_Users userBLL = new B_SECURITY_Users();
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void cmdUpdate_Click(object sender, EventArgs e)
        {
            string UserID = Session["UserSeq"].ToString();
            string NewPassword = txtNewPassword.Text.Trim();
            string ConfirmPassword = txtConfirmPassword.Text.Trim();
            bool bExist = userBLL.CheckPassword(UserID, txtOldPassword.Text.Trim());

            lblOldPassword.Visible = !bExist;
            lblConfirmPassword.Visible = (NewPassword != ConfirmPassword);

            if (!bExist)
            {
                return;
            }
            else if (NewPassword != ConfirmPassword)
            {
                return;
            }
            else 
            {
                userBLL.ChangePassword(Int32.Parse(UserID), NewPassword, SsMng.EmpSeqI);

                ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "onclick", "MessageAlert('คุณได้ทำการเปลี่ยนรหัสผ่านเรียบร้อยแล้ว')", true);
                Response.Redirect(@"~\App_UI\Forms\Default.aspx");
            }
        }
    }
}
